package com.ruoyi.mng.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mng.domain.HzChaChannel;
import com.ruoyi.mng.service.IHzChaChannelService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 渠道管理Controller
 * 
 * @author chenqiang
 * @date 2023-04-28
 */
@Controller
@RequestMapping("/mng/channel")
public class HzChaChannelController extends BaseController
{
    private String prefix = "mng/channel";

    @Autowired
    private IHzChaChannelService hzChaChannelService;

    @RequiresPermissions("mng:channel:view")
    @GetMapping()
    public String channel()
    {
        return prefix + "/channel";
    }

    /**
     * 查询渠道管理列表
     */
    @RequiresPermissions("mng:channel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HzChaChannel hzChaChannel)
    {
        startPage();
        List<HzChaChannel> list = hzChaChannelService.selectHzChaChannelList(hzChaChannel);
        return getDataTable(list);
    }

    /**
     * 导出渠道管理列表
     */
    @RequiresPermissions("mng:channel:export")
    @Log(title = "渠道管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HzChaChannel hzChaChannel)
    {
        List<HzChaChannel> list = hzChaChannelService.selectHzChaChannelList(hzChaChannel);
        ExcelUtil<HzChaChannel> util = new ExcelUtil<HzChaChannel>(HzChaChannel.class);
        return util.exportExcel(list, "渠道管理数据");
    }

    /**
     * 新增渠道管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存渠道管理
     */
    @RequiresPermissions("mng:channel:add")
    @Log(title = "渠道管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HzChaChannel hzChaChannel)
    {
        return toAjax(hzChaChannelService.insertHzChaChannel(hzChaChannel));
    }

    /**
     * 修改渠道管理
     */
    @RequiresPermissions("mng:channel:edit")
    @GetMapping("/edit/{channelId}")
    public String edit(@PathVariable("channelId") Long channelId, ModelMap mmap)
    {
        HzChaChannel hzChaChannel = hzChaChannelService.selectHzChaChannelByChannelId(channelId);
        mmap.put("hzChaChannel", hzChaChannel);
        return prefix + "/edit";
    }

    /**
     * 修改保存渠道管理
     */
    @RequiresPermissions("mng:channel:edit")
    @Log(title = "渠道管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HzChaChannel hzChaChannel)
    {
        return toAjax(hzChaChannelService.updateHzChaChannel(hzChaChannel));
    }

    /**
     * 删除渠道管理
     */
    @RequiresPermissions("mng:channel:remove")
    @Log(title = "渠道管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hzChaChannelService.deleteHzChaChannelByChannelIds(ids));
    }
}
